package cn.huiyunche.base.service.interfaces;

import cn.huiyunche.base.service.model.SUser;
import cn.huiyunche.base.service.model.SUserExample;
import cn.huiyunche.base.service.vo.*;
import cn.huiyunche.tools.basic.exceptions.BusinessException;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: AuthService
 * @Description: 用户授权接口
 * @author: Aaron
 * @date: 2016年5月6日 下午2:09:39
 */

/**
 * The interface User service.
 *
 * @ClassName: UserService
 * @Description: TODO
 * @author: Aaron
 * @date: 2016年5月16日 下午5:50:19
 */
public interface UserService {

    /**
     * Add long.
     *
     * @param phone       the phone
     * @param openid      the openid
     * @param uuid        the uuid
     * @param deviceType  the device type
     * @param userType    the user type
     * @param password    密码
     * @param invitedcode the invitedcode
     * @return the long
     * @Title: add
     * @Description: 添加用户 （用户注册）
     * @return: int
     */
    Long add(String phone, String openid, String uuid, String deviceType, int userType, String password, String invitedcode);

    /**
     * Gets current user.
     *
     * @return current user
     * @throws Exception
     * @Title: getCurrentUser
     * @Description: 查询当前用户信息
     * @return: User
     */
    UserShowVo getCurrentUser() throws Exception;

    /**
     * Gets by id.
     *
     * @param id the id
     * @return by id
     * @Title: getById
     * @Description: TODO
     * @return: User
     */
    SUser getById(long id);

    /**
     * Update by id user show vo.
     *
     * @param form 更新实体
     * @return user show vo
     * @throws Exception the exception
     * @Title: updateById
     * @Description: 根据id更新user
     * @return: int
     */
    UserShowVo updateById(UserUpdateVo form) throws Exception;

    /**
     * Gets by conditions.
     *
     * @param name 手机号/用户名
     * @param pwd  密码
     * @return by conditions
     * @throws Exception the exception
     * @Title: getByConditions
     * @Description: 查询用户
     * @return: List<User>
     */
    SUser getByConditions(String name, String pwd) throws Exception;

    /**
     * Gets by phone.
     *
     * @param phone     手机号
     * @param userTypes 用户类型
     * @return by phone
     * @Title: getByPhone
     * @Description: 根据手机号 、用户类型查询用户是否已注册
     * @return: User
     */
    SUser getByPhone(String phone, List<Integer> userTypes);

    /**
     * 获取用户信息
     *
     * @param phone     手机号
     * @param userTypes 用户类型
     * @param isEnable  是否查询可用状态
     * @return 用户对象 by phone
     */
    SUser getByPhone(String phone, List<Integer> userTypes, boolean isEnable);

    /**
     * Gets by phone.
     *
     * @param phone    手机号
     * @param userType 用户类型
     * @return by phone
     * @Title: getByPhone
     * @Description: 根据手机号 、用户类型查询用户是否已注册
     * @return: User
     */
    SUser getByPhone(String phone, Integer userType);

    /**
     * Sets auth code.
     *
     * @param phone    手机号
     * @param code     验证码
     * @param seconds  有效期
     * @param userType 用户类型
     * @return auth code
     * @throws Exception the exception
     * @Title: setAuthCode
     * @Description: 存储验证码
     * @return: String
     */
    String setAuthCode(String phone, String code, int seconds, int userType) throws Exception;

    /**
     * Gets auth code.
     *
     * @param phone    手机号
     * @param userType 用户类型
     * @return auth code
     * @throws Exception the exception
     * @Title: getAuthCode
     * @Description: 根据phone获取存储的验证码
     * @return: String
     */
    String getAuthCode(String phone, int userType) throws Exception;

    /**
     * Remove authcode.
     *
     * @param key the value
     * @return the boolean
     */
    boolean removeAuthcode(String key);

    /**
     * Gets current user vo.
     *
     * @return current user vo
     * @throws BusinessException the business exception
     * @Title: getUserFromAuth
     * @Description: 解析token获取用户信息
     * @return: User
     */
    UserVo getCurrentUserVo() throws Exception;

    /**
     * 用户登录
     *
     * @param phone      the phone
     * @param userType   the user type
     * @param password   the password
     * @param deviceType the device type
     * @param openid     the openid
     * @param uuid       the uuid
     * @return s user
     * @throws BusinessException
     */
    SUser signIn(String phone, int userType, String password, String deviceType, String openid, String uuid) throws Exception;


    /**
     * 商户端PC
     *
     * @param phone
     * @param userType
     * @param password
     * @param deviceType
     * @param openid
     * @param uuid
     * @return
     * @throws Exception
     */
    SUser webSignIn(String phone, int userType, String password, String deviceType, String openid, String uuid) throws Exception;

    /**
     * 用户登录
     *
     * @param phone      the phone
     * @param userType   the user type
     * @param password   the password
     * @param deviceType the device type
     * @param openid     the openid
     * @param uuid       the uuid
     * @param pushid     the pushid
     * @return s user
     * @throws BusinessException
     */
    SUser signIn(String phone, int userType, String password, String deviceType, String openid, String uuid, String pushid, String clientType) throws Exception;

    /**
     * 重置密码
     *
     * @param phone    the phone
     * @param userType the user type
     * @param password the password
     * @return int int
     * @throws Exception
     */
    int resetPwd(String phone, int userType, String password) throws Exception;

    /**
     * 微信退出
     *
     * @return int int
     * @throws BusinessException the business exception
     */
    int cleanOpenId() throws Exception;

    /**
     * 上线下线
     *
     * @param status the status
     * @return int int
     * @throws BusinessException the business exception
     */
    int modifyUserStatus(int status) throws Exception;

    /**
     * Bind wechat user show vo.
     *
     * @param form 更新实体
     * @return user show vo
     * @throws BusinessException the business exception
     * @Title: bindWechat
     * @Description: 绑定微信
     * @return: UserShowVo
     */
    UserShowVo bindWechat(UserUpdateVo form) throws Exception;

    /**
     * Count by example integer.
     *
     * @param search the search
     * @return the integer
     */
    Integer countByExample(SUserExample search);

    /**
     * Select by example list.
     *
     * @param search the search
     * @return the list
     */
    List<SUser> selectByExample(SUserExample search);

    /**
     * Select by primary key s user.
     *
     * @param userId the user id
     * @return the s user
     */
    SUser selectByPrimaryKey(Long userId);

    /**
     * Is driver equal to current user boolean.
     *
     * @param id the id
     * @return boolean boolean
     * @Title: isDriverEqualToCurrentUser
     * @Description: 判断当前用户是否是承运人
     * @return: boolean
     */
    boolean isDriverEqualToCurrentUser(Long id) throws Exception;

    /**
     * 查询司机是否认证通过
     *
     * @param phone 司机手机号
     * @return result result
     */
    Result<Map<String, Object>> isCertifithrough(String phone);

    /**
     * 用户校验
     *
     * @return 结果集 result
     */
    Result<String> checkUser() throws Exception;

    /**
     * 抽奖用户校验
     *
     * @return 结果集 result
     */
    Result<Object> checkDrawUser() throws Exception;

    /**
     * 用户升级为企业账户（托运端）
     *
     * @param code 公司验证码
     * @return user show vo
     * @throws Exception the exception
     */
    UserShowVo upgrades(String code) throws Exception;

    /**
     * 更新用户
     *
     * @param user the user
     * @return int int
     */
    int updateByRecord(SUser user);

    /**
     * 刷新排队
     *
     * @return map map
     * @throws BusinessException the business exception
     */
    Map<String, Object> refresh() throws Exception;

    /**
     * 人送车－上线
     *
     * @return map map
     * @throws BusinessException the business exception
     */
    Map<String, Object> online() throws Exception;

    /**
     * 人送车－下线
     *
     * @return int int
     * @throws BusinessException the business exception
     */
    int offline() throws Exception;

    /**
     * 检测用户是否为tms用户
     *
     * @param phone 手机号，如果不传递手机号则查询当前用户
     * @return 是否为tms用户 boolean
     */
    public Boolean isTmsUser(String phone) throws Exception;

    /**
     * 查询当前用户
     *
     * @return current user info
     * @throws BusinessException the business exception
     */
    UserShowVo getCurrentUserInfo() throws Exception;

    /**
     * 更新用户信息
     *
     * @param form the form
     * @return user show vo
     * @throws BusinessException the business exception
     */
    UserShowVo updateUserInfo(UserUpdateVo form) throws Exception;

    /**
     * 用户当前位置
     *
     * @param upv the upv
     * @return long long
     * @throws BusinessException the business exception
     */
    Long addUserPosition(UserPositionVo upv) throws Exception;

    /**
     * 人送项目 开通司机账号
     *
     * @param phone the phone
     * @return result result
     */
    Result<String> openAccount(String phone);

    /**
     * 人送项目 禁用司机账号
     *
     * @param phone the phone
     * @return result result
     */
    Result<String> disableAccount(String phone);

    /**
     * 人送项目 根据用户手机号 查询司机信息
     *
     * @param phone the phone
     * @return user by phone
     */
    SUser getUserByPhone(String phone);

    /**
     * Gets by ids.
     *
     * @param subUserIds the sub user ids
     * @return the by ids
     */
    List<SUser> getByIds(List<Long> subUserIds);

    /**
     * Gets drivers by s user id for supplier.
     * 根据用户主键查询用户驾照信息
     *
     * @param page    the page
     * @param userIds the user ids
     * @return the user driver by s user id for supplier
     */
    Map<String, Object> getDriversBySUserIdForSupplier(PageVo page, List<Long> userIds);

    /**
     * 添加分供方用户
     *
     * @param updateVo the update vo
     * @param password the password
     * @return result result
     * @throws BusinessException the business exception
     */
    Result<Integer> modifySubsuppliers(UserUpdateVo updateVo, String password) throws Exception;

    /**
     * 分供方列表
     *
     * @param pageVo the page vo
     * @param showVo the show vo
     * @return result result
     * @throws BusinessException the business exception
     */
    Result<Map<String, Object>> subsupplierList(PageVo pageVo, UserShowVo showVo) throws Exception;

    /**
     * 分供方列表
     *
     * @return result result
     * @throws BusinessException the business exception
     */
    Result<List<SUser>> subList() throws Exception;

    /**
     * Gets users by type.
     *
     * @param userType the user type
     * @return the users by type
     */
    List<SUser> getUsersByType(int userType);

    /**
     * Gets user ids by type.
     *
     * @param userType the user type
     * @return the user ids by type
     */
    List<Long> getUserIdsByType(int userType);

    /**
     * 司机端查询当前用户
     *
     * @param truckType the truck type
     * @return current user for driver
     */
    UserShowVo getCurrentUserForDriver(Boolean truckType) throws Exception;

    /**
     * Already esists boolean.
     *
     * @param phone    the phone
     * @param userType the user type
     * @return the boolean
     */
    boolean alreadyExists(String phone, int userType);


    /**
     * @Title: 构建USER的VO对象
     * @Description: TODO
     * @param user
     * @param vo
     * @return: void
     */
    public void buildUserShowVo(SUser user, UserShowVo vo);


    /**
     * Select Users by Condition but not paging
     *
     * @param phone
     * @return
     */
    List<DUserVo> selectByCondition(String phone);

    /**
     * Update Pic by Id
     *
     * @param id
     * @param pic
     * @return
     */
    int updatePicById(Long id, String pic);
}
